package com.ugoodtech.mdcc.client.controller;

import com.ugoodtech.mdcc.client.dto.JsonResponse;
import com.ugoodtech.mdcc.client.service.ComplaintReportLogService;
import com.ugoodtech.mdcc.core.domain.User;
import com.ugoodtech.mdcc.core.repository.UserRepository;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.security.Principal;

@Api(description = "投诉单历史相关接口")
@RestController
@RequestMapping("/complaintReportLogController")
public class ComplaintReportLogController {

    @Autowired
    private ComplaintReportLogService complaintReportLogService;

    @Autowired
    private UserRepository userRepository;

    @ApiOperation("获取投诉报告历史记录")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页数", paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "size", value = "每页条数", paramType = "query", dataType = "int"),
    })
    @RequestMapping(value = "getLogList", method = RequestMethod.GET)
    public JsonResponse getLogList(@ApiIgnore Principal principal,
                                   @ApiParam("投诉报告ID") @RequestParam(value = "complaintReportId") Long complaintReportId,
                                   Pageable pageable) {
        if (principal == null) {
            return JsonResponse.errorResponseWithError("抱歉", "invalid_token");
        }
        User clientUser = userRepository.findByUsername(principal.getName());
        if (clientUser == null) {
            return JsonResponse.errorResponseWithError("抱歉", "未找到此用户");
        }
        return complaintReportLogService.getLogList(complaintReportId, pageable);
    }


}
